 
use "$path\datasets\rd_dataset.dta", clear
keep if in_rdd_sample==1



gen close_female=(margin_1<=0.05 & margin_1>=0) if margin_1<.
gen close_male=(margin_1>=-0.05 & margin_1<0) if margin_1<.
gen non_close_female=(margin_1>0.05 & margin_1<.) if margin_1<.
gen non_close_male=(margin_1<-0.05) if margin_1<.




 
ivreg csu close_male close_female  non_close_female , r cluster(gkz)
est store m1
sum csu if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg spd  close_male close_female  non_close_female, r cluster(gkz)
est store m2
sum spd if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg greens close_male close_female  non_close_female , r cluster(gkz)
est store m3
sum greens if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg higher_degree close_male close_female  non_close_female , r cluster(gkz)
est store m4
sum higher_degree if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg employed close_male close_female  non_close_female , r cluster(gkz)
est store m5
sum employed if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg  selfemployed close_male close_female  non_close_female , r cluster(gkz)
est store m6
sum selfemployed if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg  student close_male close_female  non_close_female , r cluster(gkz)
est store m7
sum student if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg  retired close_male close_female  non_close_female , r cluster(gkz)
est store m8
sum retired if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg  alter close_male close_female  non_close_female , r cluster(gkz)
est store m9
sum alter if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)









esttab  m1 m2 m3 m4 m5 m6 m7 m8 m9 using TableA27/tableA27_PanelA.txt, replace order( ) mlabel(,none) ///
cells(b(label(coef.) star fmt(%8.3f) ) se(label((z)) par fmt(%6.3f))) ///
collabels(none) ///
  keep (close_male close_female  non_close_female   ) ///
  stats( N   N_clust mean_depvar sd_depvar , layout( @  @  `""@ (@)""' )  fmt(  %9.0g %9.0g  %9.2f %9.2f  ) ///
 labels(  "N"  "Municipalities" "Mean (SD)"  )) ///
starlevels(* 0.10 ** 0.05 *** 0.01) ///
  indicate( ) style(tab) ///
  varlabels(  close_male "Close male winner" close_female  "Close female winner" non_close_female "Non-close female winner")



************************************************************************************************************************************


